package ACWing._830_单调栈;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        Deque<Integer> stack = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            // 栈顶若大于当前值，则出栈直至栈顶小于当前值或为空
            while (!stack.isEmpty()&&stack.peek()>= a[i]){
                stack.pop();
            }
            if(stack.isEmpty()) {
                ans[i] = -1;
            }else {
                ans[i] = stack.peek();
            }
            stack.push(a[i]);

        }
        System.out.print(ans[0]);
        for (int i = 1; i < n; i++) {
            System.out.print(" "+ans[i]);
        }
        scanner.close();
    }
}
